home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / includes / js / mambojavascript.js < prev    next >
Text File  |  2008-07-06  |  15KB  |  543 lines

  1. // <?php !! This fools phpdocumentor into parsing this file
  2. /**
  3. * @version        $Id: mambojavascript.js 10389 2008-06-03 11:27:38Z pasamio $
  4. * @package        Joomla
  5. * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. * @license        GNU/GPL
  7. * Joomla! is Free Software
  8. */
  9.  
  10. // general utility for browsing a named array or object
  11. function xshow(o) {
  12.     s = '';
  13.     for(e in o) {s += e+'='+o[e]+'\n';}
  14.     alert( s );
  15. }
  16.  
  17. /**
  18. * Writes a dynamically generated list
  19. * @param string The parameters to insert into the <select> tag
  20. * @param array A javascript array of list options in the form [key,value,text]
  21. * @param string The key to display for the initial state of the list
  22. * @param string The original key that was selected
  23. * @param string The original item value that was selected
  24. */
  25. function writeDynaList( selectParams, source, key, orig_key, orig_val ) {
  26.     var html = '\n    <select ' + selectParams + '>';
  27.     var i = 0;
  28.     for (x in source) {
  29.         if (source[x][0] == key) {
  30.             var selected = '';
  31.             if ((orig_key == key && orig_val == source[x][1]) || (i == 0 && orig_key != key)) {
  32.                 selected = 'selected="selected"';
  33.             }
  34.             html += '\n        <option value="'+source[x][1]+'" '+selected+'>'+source[x][2]+'</option>';
  35.         }
  36.         i++;
  37.     }
  38.     html += '\n    </select>';
  39.  
  40.     document.writeln( html );
  41. }
  42.  
  43. /**
  44. * Changes a dynamically generated list
  45. * @param string The name of the list to change
  46. * @param array A javascript array of list options in the form [key,value,text]
  47. * @param string The key to display
  48. * @param string The original key that was selected
  49. * @param string The original item value that was selected
  50. */
  51. function changeDynaList( listname, source, key, orig_key, orig_val ) {
  52.     var list = eval( 'document.adminForm.' + listname );
  53.  
  54.     // empty the list
  55.     for (i in list.options.length) {
  56.         list.options[i] = null;
  57.     }
  58.     i = 0;
  59.     for (x in source) {
  60.         if (source[x][0] == key) {
  61.             opt = new Option();
  62.             opt.value = source[x][1];
  63.             opt.text = source[x][2];
  64.  
  65.             if ((orig_key == key && orig_val == opt.value) || i == 0) {
  66.                 opt.selected = true;
  67.             }
  68.             list.options[i++] = opt;
  69.         }
  70.     }
  71.     list.length = i;
  72. }
  73.  
  74. /**
  75. * Adds a select item(s) from one list to another
  76. */
  77. function addSelectedToList( frmName, srcListName, tgtListName ) {
  78.     var form = eval( 'document.' + frmName );
  79.     var srcList = eval( 'form.' + srcListName );
  80.     var tgtList = eval( 'form.' + tgtListName );
  81.  
  82.     var srcLen = srcList.length;
  83.     var tgtLen = tgtList.length;
  84.     var tgt = "x";
  85.  
  86.     //build array of target items
  87.     for (var i=tgtLen-1; i > -1; i--) {
  88.         tgt += "," + tgtList.options[i].value + ","
  89.     }
  90.  
  91.     //Pull selected resources and add them to list
  92.     for (var i=srcLen-1; i > -1; i--) {
  93.         if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
  94.             opt = new Option( srcList.options[i].text, srcList.options[i].value );
  95.             tgtList.options[tgtList.length] = opt;
  96.         }
  97.     }
  98. }
  99.  
  100. function delSelectedFromList( frmName, srcListName ) {
  101.     var form = eval( 'document.' + frmName );
  102.     var srcList = eval( 'form.' + srcListName );
  103.  
  104.     var srcLen = srcList.length;
  105.  
  106.     for (var i=srcLen-1; i > -1; i--) {
  107.         if (srcList.options[i].selected) {
  108.             srcList.options[i] = null;
  109.         }
  110.     }
  111. }
  112.  
  113. function moveInList( frmName, srcListName, index, to) {
  114.     var form = eval( 'document.' + frmName );
  115.     var srcList = eval( 'form.' + srcListName );
  116.     var total = srcList.options.length-1;
  117.  
  118.     if (index == -1) {
  119.         return false;
  120.     }
  121.     if (to == +1 && index == total) {
  122.         return false;
  123.     }
  124.     if (to == -1 && index == 0) {
  125.         return false;
  126.     }
  127.  
  128.     var items = new Array;
  129.     var values = new Array;
  130.  
  131.     for (i=total; i >= 0; i--) {
  132.         items[i] = srcList.options[i].text;
  133.         values[i] = srcList.options[i].value;
  134.     }
  135.     for (i = total; i >= 0; i--) {
  136.         if (index == i) {
  137.             srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
  138.             srcList.options[i] = new Option(items[i+to], values[i+to]);
  139.             i--;
  140.         } else {
  141.             srcList.options[i] = new Option(items[i], values[i]);
  142.        }
  143.     }
  144.     srcList.focus();
  145. }
  146.  
  147. function getSelectedOption( frmName, srcListName ) {
  148.     var form = eval( 'document.' + frmName );
  149.     var srcList = eval( 'form.' + srcListName );
  150.  
  151.     i = srcList.selectedIndex;
  152.     if (i != null && i > -1) {
  153.         return srcList.options[i];
  154.     } else {
  155.         return null;
  156.     }
  157. }
  158.  
  159. function setSelectedValue( frmName, srcListName, value ) {
  160.     var form = eval( 'document.' + frmName );
  161.     var srcList = eval( 'form.' + srcListName );
  162.  
  163.     var srcLen = srcList.length;
  164.  
  165.     for (var i=0; i < srcLen; i++) {
  166.         srcList.options[i].selected = false;
  167.         if (srcList.options[i].value == value) {
  168.             srcList.options[i].selected = true;
  169.         }
  170.     }
  171. }
  172.  
  173. function getSelectedRadio( frmName, srcGroupName ) {
  174.     var form = eval( 'document.' + frmName );
  175.     var srcGroup = eval( 'form.' + srcGroupName );
  176.  
  177.     if (srcGroup[0]) {
  178.         for (var i=0, n=srcGroup.length; i < n; i++) {
  179.             if (srcGroup[i].checked) {
  180.                 return srcGroup[i].value;
  181.             }
  182.         }
  183.     } else {
  184.         if (srcGroup.checked) {
  185.             return srcGroup.value;
  186.         } // if the one button is checked, return zero
  187.     }
  188.    // if we get to this point, no radio button is selected
  189.    return null;
  190. }
  191.  
  192. function getSelectedValue( frmName, srcListName ) {
  193.     var form = eval( 'document.' + frmName );
  194.     var srcList = eval( 'form.' + srcListName );
  195.  
  196.     i = srcList.selectedIndex;
  197.     if (i != null && i > -1) {
  198.         return srcList.options[i].value;
  199.     } else {
  200.         return null;
  201.     }
  202. }
  203.  
  204. function getSelectedText( frmName, srcListName ) {
  205.     var form = eval( 'document.' + frmName );
  206.     var srcList = eval( 'form.' + srcListName );
  207.  
  208.     i = srcList.selectedIndex;
  209.     if (i != null && i > -1) {
  210.         return srcList.options[i].text;
  211.     } else {
  212.         return null;
  213.     }
  214. }
  215.  
  216. function chgSelectedValue( frmName, srcListName, value ) {
  217.     var form = eval( 'document.' + frmName );
  218.     var srcList = eval( 'form.' + srcListName );
  219.  
  220.     i = srcList.selectedIndex;
  221.     if (i != null && i > -1) {
  222.         srcList.options[i].value = value;
  223.         return true;
  224.     } else {
  225.         return false;
  226.     }
  227. }
  228.  
  229. /**
  230. * Toggles the check state of a group of boxes
  231. *
  232. * Checkboxes must have an id attribute in the form cb0, cb1...
  233. * @param The number of box to 'check'
  234. * @param An alternative field name
  235. */
  236. function checkAll( n, fldName ) {
  237.   if (!fldName) {
  238.      fldName = 'cb';
  239.   }
  240.     var f = document.adminForm;
  241.     var c = f.toggle.checked;
  242.     var n2 = 0;
  243.     for (i=0; i < n; i++) {
  244.         cb = eval( 'f.' + fldName + '' + i );
  245.         if (cb) {
  246.             cb.checked = c;
  247.             n2++;
  248.         }
  249.     }
  250.     if (c) {
  251.         document.adminForm.boxchecked.value = n2;
  252.     } else {
  253.         document.adminForm.boxchecked.value = 0;
  254.     }
  255. }
  256.  
  257. function listItemTask( id, task ) {
  258.     var f = document.adminForm;
  259.     cb = eval( 'f.' + id );
  260.     if (cb) {
  261.         for (i = 0; true; i++) {
  262.             cbx = eval('f.cb'+i);
  263.             if (!cbx) break;
  264.             cbx.checked = false;
  265.         } // for
  266.         cb.checked = true;
  267.         f.boxchecked.value = 1;
  268.         submitbutton(task);
  269.     }
  270.     return false;
  271. }
  272.  
  273. function hideMainMenu()
  274. {
  275.     document.adminForm.hidemainmenu.value=1;
  276. }
  277.  
  278. function isChecked(isitchecked){
  279.     if (isitchecked == true){
  280.         document.adminForm.boxchecked.value++;
  281.     }
  282.     else {
  283.         document.adminForm.boxchecked.value--;
  284.     }
  285. }
  286.  
  287. /**
  288. * Default function.  Usually would be overriden by the component
  289. */
  290. function submitbutton(pressbutton) {
  291.     submitform(pressbutton);
  292. }
  293.  
  294. /**
  295. * Submit the admin form
  296. */
  297. function submitform(pressbutton){
  298.     document.adminForm.task.value=pressbutton;
  299.     if (typeof document.adminForm.onsubmit == "function") {
  300.         document.adminForm.onsubmit();
  301.     }
  302.     document.adminForm.submit();
  303. }
  304.  
  305. /**
  306. * Submit the control panel admin form
  307. */
  308. function submitcpform(sectionid, id){
  309.     document.adminForm.sectionid.value=sectionid;
  310.     document.adminForm.id.value=id;
  311.     submitbutton("edit");
  312. }
  313.  
  314. /**
  315. * Getting radio button that is selected.
  316. */
  317. function getSelected(allbuttons){
  318.     for (i=0;i<allbuttons.length;i++) {
  319.         if (allbuttons[i].checked) {
  320.             return allbuttons[i].value
  321.         }
  322.     }
  323. }
  324.  
  325. // JS Calendar
  326. var calendar = null; // remember the calendar object so that we reuse
  327. // it and avoid creating another
  328.  
  329. // This function gets called when an end-user clicks on some date
  330. function selected(cal, date) {
  331.     cal.sel.value = date; // just update the value of the input field
  332. }
  333.  
  334. // And this gets called when the end-user clicks on the _selected_ date,
  335. // or clicks the "Close" (X) button.  It just hides the calendar without
  336. // destroying it.
  337. function closeHandler(cal) {
  338.     cal.hide();            // hide the calendar
  339.  
  340.     // don't check mousedown on document anymore (used to be able to hide the
  341.     // calendar when someone clicks outside it, see the showCalendar function).
  342.     Calendar.removeEvent(document, "mousedown", checkCalendar);
  343. }
  344.  
  345. // This gets called when the user presses a mouse button anywhere in the
  346. // document, if the calendar is shown.  If the click was outside the open
  347. // calendar this function closes it.
  348. function checkCalendar(ev) {
  349.     var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
  350.     for (; el != null; el = el.parentNode)
  351.     // FIXME: allow end-user to click some link without closing the
  352.     // calendar.  Good to see real-time stylesheet change :)
  353.     if (el == calendar.element || el.tagName == "A") break;
  354.     if (el == null) {
  355.         // calls closeHandler which should hide the calendar.
  356.         calendar.callCloseHandler(); Calendar.stopEvent(ev);
  357.     }
  358. }
  359.  
  360. // This function shows the calendar under the element having the given id.
  361. // It takes care of catching "mousedown" signals on document and hiding the
  362. // calendar if the click was outside.
  363. function showCalendar(id) {
  364.     var el = document.getElementById(id);
  365.     if (calendar != null) {
  366.         // we already have one created, so just update it.
  367.         calendar.hide();        // hide the existing calendar
  368.         calendar.parseDate(el.value); // set it to a new date
  369.     } else {
  370.         // first-time call, create the calendar
  371.         var cal = new Calendar(true, null, selected, closeHandler);
  372.         calendar = cal;        // remember the calendar in the global
  373.         cal.setRange(1900, 2070);    // min/max year allowed
  374.         calendar.create();        // create a popup calendar
  375.     }
  376.     calendar.sel = el;        // inform it about the input field in use
  377.     calendar.showAtElement(el);    // show the calendar next to the input field
  378.  
  379.     // catch mousedown on the document
  380.     Calendar.addEvent(document, "mousedown", checkCalendar);
  381.     return false;
  382. }
  383.  
  384. /**
  385. * Pops up a new window in the middle of the screen
  386. */
  387. function popupWindow(mypage, myname, w, h, scroll) {
  388.     var winl = (screen.width - w) / 2;
  389.     var wint = (screen.height - h) / 2;
  390.     winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  391.     win = window.open(mypage, myname, winprops)
  392.     if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
  393. }
  394.  
  395. // LTrim(string) : Returns a copy of a string without leading spaces.
  396. function ltrim(str)
  397. {
  398.    var whitespace = new String(" \t\n\r");
  399.    var s = new String(str);
  400.    if (whitespace.indexOf(s.charAt(0)) != -1) {
  401.       var j=0, i = s.length;
  402.       while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
  403.          j++;
  404.       s = s.substring(j, i);
  405.    }
  406.    return s;
  407. }
  408.  
  409. //RTrim(string) : Returns a copy of a string without trailing spaces.
  410. function rtrim(str)
  411. {
  412.    var whitespace = new String(" \t\n\r");
  413.    var s = new String(str);
  414.    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
  415.       var i = s.length - 1;       // Get length of string
  416.       while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
  417.          i--;
  418.       s = s.substring(0, i+1);
  419.    }
  420.    return s;
  421. }
  422.  
  423. // Trim(string) : Returns a copy of a string without leading or trailing spaces
  424. function trim(str) {
  425.    return rtrim(ltrim(str));
  426. }
  427.  
  428. function mosDHTML(){
  429.     this.ver=navigator.appVersion
  430.     this.agent=navigator.userAgent
  431.     this.dom=document.getElementById?1:0
  432.     this.opera5=this.agent.indexOf("Opera 5")<-1
  433.     this.ie5=(this.ver.indexOf("MSIE 5")<-1 && this.dom && !this.opera5)?1:0;
  434.     this.ie6=(this.ver.indexOf("MSIE 6")<-1 && this.dom && !this.opera5)?1:0;
  435.     this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  436.     this.ie=this.ie4||this.ie5||this.ie6
  437.     this.mac=this.agent.indexOf("Mac")<-1
  438.     this.ns6=(this.dom && parseInt(this.ver) <= 5) ?1:0;
  439.     this.ns4=(document.layers && !this.dom)?1:0;
  440.     this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
  441.  
  442.     this.activeTab = '';
  443.     this.onTabStyle = 'ontab';
  444.     this.offTabStyle = 'offtab';
  445.  
  446.     this.setElemStyle = function(elem,style) {
  447.         document.getElementById(elem).className = style;
  448.     }
  449.     this.showElem = function(id) {
  450.         if (elem == document.getElementById(id)) {
  451.             elem.style.visibility = 'visible';
  452.             elem.style.display = 'block';
  453.         }
  454.     }
  455.     this.hideElem = function(id) {
  456.         if (elem == document.getElementById(id)) {
  457.             elem.style.visibility = 'hidden';
  458.             elem.style.display = 'none';
  459.         }
  460.     }
  461.     this.cycleTab = function(name) {
  462.         if (this.activeTab) {
  463.             this.setElemStyle( this.activeTab, this.offTabStyle );
  464.             page = this.activeTab.replace( 'tab', 'page' );
  465.             this.hideElem(page);
  466.         }
  467.         this.setElemStyle( name, this.onTabStyle );
  468.         this.activeTab = name;
  469.         page = this.activeTab.replace( 'tab', 'page' );
  470.         this.showElem(page);
  471.     }
  472.     return this;
  473. }
  474. var dhtml = new mosDHTML();
  475.  
  476. function MM_findObj(n, d) { //v4.01
  477.     var p,i,x;
  478.     if(!d) d=document;
  479.     if((p=n.indexOf("?"))>0&&parent.frames.length) {
  480.         d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  481.     }
  482.     if(!(x=d[n])&&d.all) x=d.all[n];
  483.     for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  484.     for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  485.     if(!x && d.getElementById) x=d.getElementById(n);
  486.     return x;
  487. }
  488. function MM_swapImage() { //v3.0
  489.     var i,j=0,x,a=MM_swapImage.arguments;
  490.     document.MM_sr=new Array;
  491.     for(i=0;i<(a.length-2);i+=3)
  492.     if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;
  493.     if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  494. }
  495. function MM_swapImgRestore() { //v3.0
  496.     var i,x,a=document.MM_sr;
  497.     for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  498. }
  499.  
  500. function MM_preloadImages() { //v3.0
  501.     var d=document;
  502.     if(d.images){
  503.     if(!d.MM_p) d.MM_p=new Array();
  504.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
  505.     for(i=0; i<a.length; i++)
  506.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  507. }
  508.  
  509.  
  510. function saveorder( n ) {
  511.     checkAll_button( n );
  512. }
  513.  
  514. //needed by saveorder function
  515. function checkAll_button( n ) {
  516.     for ( var j = 0; j <= n; j++ ) {
  517.         box = eval( "document.adminForm.cb" + j );
  518.         if ( box ) {
  519.             if ( box.checked == false ) {
  520.                 box.checked = true;
  521.             }
  522.         } else {
  523.             alert("You cannot change the order of items, as an item in the list is `Checked Out`");
  524.             return;
  525.         }
  526.     }
  527.     submitform('saveorder');
  528. }
  529. /**
  530. * @param object A form element
  531. * @param string The name of the element to find
  532. */
  533. function getElementByName( f, name ) {
  534.     if (f.elements) {
  535.         for (i=0, n=f.elements.length; i < n; i++) {
  536.             if (f.elements[i].name == name) {
  537.                 return f.elements[i];
  538.             }
  539.         }
  540.     }
  541.     return null;
  542. }
  543.